package com.deluxelx.soul.inn.web.counselor;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.deluxelx.soul.inn.bean.counselor.*;
import com.deluxelx.soul.inn.common.param.CollectedParam;
import com.deluxelx.soul.inn.common.result.SoulInnResult;
import com.deluxelx.soul.inn.service.counselor.CounselorService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 咨询师 Controller
 *
 * @author: zihao.liao
 * @date: 2024/3/23 20:02
 */
@RestController
@RequestMapping("/soul/inn/counselor")
public class CounselorController {

    @Resource
    private CounselorService counselorService;

    @GetMapping("/counselorDetail")
    public SoulInnResult<CounselorDetailVO> fetchCounselorDetail(String counselorId, String userId) {
        CounselorDetailVO counselorDetailVO = counselorService.fetchCounselorDetail(counselorId, userId);
        if (ObjectUtil.isNotEmpty(counselorDetailVO)) {
            return SoulInnResult.success(counselorDetailVO);
        }
        return SoulInnResult.fail("获取咨询师详情失败！");
    }

    @PostMapping("/isCollected")
    public SoulInnResult<Boolean> isCollected(@RequestBody CollectedParam param) {
        try {
            Boolean isCollected = counselorService.isCollectCounselor(param);
            return SoulInnResult.success(isCollected);
        } catch (Exception e) {
            return SoulInnResult.fail("获取收藏状态失败！");
        }
    }

    @PostMapping("/followCounselor")
    public SoulInnResult<Boolean> followCounselor(@RequestBody CollectedParam param) {
        try {
            Boolean isSuccess = counselorService.followCounselor(param);
            return SoulInnResult.success(isSuccess);
        } catch (Exception e) {
            return SoulInnResult.fail("关注失败！");
        }
    }

    @PostMapping("/unFollowCounselor")
    public SoulInnResult<Boolean> unFollowCounselor(@RequestBody CollectedParam param) {
        try {
            Boolean isSuccess = counselorService.unFollowCounselor(param);
            return SoulInnResult.success(isSuccess);
        } catch (Exception e) {
            return SoulInnResult.fail("取消关注失败！");
        }
    }

    @PostMapping("/fetchByCondition")
    public SoulInnResult<List<CounselorVO>> fetchByCondition(@RequestBody CounselorQueryParam param) {
        List<CounselorVO> counselorVOS = counselorService.fetchByCondition(param);
        if (CollectionUtil.isNotEmpty(counselorVOS)) {
            return SoulInnResult.success(counselorVOS);
        }
        return SoulInnResult.fail("根据条件查询咨询师失败");
    }

    @GetMapping("/gradeList")
    public SoulInnResult<List<Grade>> fetchGradeList() {
        return SoulInnResult.success(counselorService.fetchGradeList());
    }

    @GetMapping("/expertList")
    public SoulInnResult<List<Expertise>> fetchExpertList() {
        return SoulInnResult.success(counselorService.fetchExpertiseList());
    }

    @PostMapping("/certified")
    public SoulInnResult<Boolean> certified(@RequestBody CertifiedParam param) {
        if (counselorService.certified(param)) {
            return SoulInnResult.success(true);
        }
        return SoulInnResult.fail("咨询师认证失败！");
    }

    @GetMapping("/fetchSchedule")
    public SoulInnResult<List<ScheduleTime>> fetchSchedule(String counselorId) {
        return SoulInnResult.success(counselorService.fetchScheduleById(counselorId));
    }

    @PostMapping("/makeAppointment")
    public SoulInnResult<Boolean> makeAppointment(@RequestBody AppointmentParam param) {
        if (counselorService.makeAppointment(param)) {
            return SoulInnResult.success(true);
        }
        return SoulInnResult.fail("预约失败");
    }

}
